home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / grafix / mpeg / easy_mpeg102.lha / EasyMPEG / Easy_MPEG.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1994-10-15  |  18.0 KB  |  704 lines

  1. /* ******************* Easy_MPEG Version 1.00 *********************** */
  2. /* *******************    Scott A. Tribbey    *********************** */
  3. /* *******************      July 21,1994      *********************** */
  4.  
  5. /* Painless MPEG! Yup this should make it easy for anybody */
  6. /* to create their own MPEG movies */
  7.  
  8. /* AREXX script for making MPEG-1 video streams using */
  9. /* the Berkley University MPEG-1 encoder for the Amiga */
  10. /* This macro will create the MPEG-1 stream from 24bit frames */
  11. /* that have been or are being created by a ray tracer or */
  12. /* other graphics output program */
  13.  
  14. /* The program uses the MPEG-1 encoder to create individual GOPS */
  15. /* or 'Groups Of Pictures' as another application produces the frames */
  16. /* In this way, hard drive space is conserved, as everytime the */
  17. /* number of produced frames available is enough to encode a GOP */
  18. /* the frames will be converted to a GOP and deleted */
  19. /* This allows for very large animations to be constructed on a */
  20. /* system with only modest hard drive space */
  21.  
  22. /* TRACE('results') */
  23.  
  24.  
  25.  
  26.  
  27. IF ARG() = 1 THEN
  28.   DO
  29.  
  30.     IF EXISTS( 'MPEG.settings' ) THEN
  31.        DO
  32.           Call ReadParams()
  33.           GOPS_COMPLETE = 0   /* Just here to initialize variable */
  34.        END
  35.     ELSE
  36.        Call InitGlobals()
  37.  
  38.     PARSE ARG FrameName StFrame EndFrame Xdim Ydim OutFile FrmDelay DelOldFrms .
  39.  
  40.     IF FrameName == '?' THEN
  41.       DO
  42.         SAY 'Usage: rx Easy_MPEG Base_Frame_Name Start End Xdim Ydim '
  43.         SAY '                    OutFileName Delay DelOldFrames'
  44.         SAY
  45.         SAY 'Example: rx Make_MPEG dh0:IFF/Frame. 0000 0030 352 240 Movie 30 YES'
  46.         SAY '         creates Movie.mpg from:'
  47.         SAY '         dh0:IFF/Frame.0000 through dh0:IFF/Frame.0030'
  48.         SAY '         resolution is 352 by 240, directory scan every 30 sec.'
  49.         SAY '         original IFF files will be deleted'
  50.         SAY
  51.         EXIT    /* Quit here */
  52.       END
  53.  
  54.     Call GetFileInDir()
  55.     Call GetFrameName()
  56.     Call CalcGOPS()
  57.  
  58.   END
  59. ELSE
  60.   DO
  61.  
  62.     IF EXISTS( 'MPEG.settings' ) THEN
  63.      DO
  64.        Call ReadParams()
  65.        Call GetFileInDir()
  66.        Call CalcGOPS()
  67.        GOPS_COMPLETE = 0   /* Just here to initialize variable */
  68.        Call Stats()
  69.        Call RunHost()
  70.      END
  71.     ELSE
  72.      DO
  73.        Call InitGlobals()
  74.        Call CalcGOPS()
  75.        Call Stats()
  76.        Call RunHost()
  77.      END
  78.  
  79.   END
  80.  
  81. /* Save Parameters in the MPEG.settings file for future reference in case this session
  82.    gets interrupted */
  83.  
  84. Call SaveParams()
  85.  
  86. /* This first section is where the program checks to see if any of */
  87. /* the work is already done.  If any GOP's have been produced, then */
  88. /* the program starts from where it was last interrupted */
  89.  
  90. Error = 0
  91.  
  92. DO I = 0 to TOT_GOPS - 1 UNTIL Error = 1
  93.    IF ~ EXISTS(InputDir || OutFile || '.mpg' || '.gop.' || I)
  94.       THEN Error = 1
  95. END
  96.  
  97. GOPS_COMPLETE = I
  98.  
  99.  
  100. Call Stats()
  101.  
  102. Call WriteParamFile()
  103.  
  104.  
  105. /* change HOST address to AmigaDOS and set a decent size stack */
  106.  
  107. ADDRESS ('COMMAND')
  108. 'Stack 30000'
  109.  
  110.  
  111. /* Wait for and create individual GOPS as frames are available */
  112. /* This will run forever if it never gets all the appropriate frames */
  113. /* Pressing CTRL-C here will break the program */
  114.  
  115. /* Main loop where frames are scanned for */
  116.  
  117. DO UNTIL GOPS_COMPLETE == TOT_GOPS
  118.  
  119. SAY 'Waiting for Frames for GOP 'GOPS_COMPLETE
  120. SAY '***** PRESS CTRL-C TO ABORT *****'
  121.  
  122.  
  123. LastGOPFrm = StFrame + (GOPS_COMPLETE * GOP_SIZE) + GOP_SIZE
  124.  
  125. IF LastGOPFrm > EndFrame THEN
  126.    LastGOPFrm = EndFrame
  127.  
  128. /* Create ZERO padded frame number for file name */
  129. FrmNumber = RIGHT(LastGOPFrm,LENGTH(StFrame),0)
  130.  
  131. SAY 'Waiting for' FrameName || FrmNumber
  132. SAY ''
  133.  
  134. IF EXISTS( InputDir || FrameName || FrmNumber ) THEN
  135.     DO
  136.  
  137.         /* Check if this is the last frame of the animation */
  138.         /* if it is, then we must check it by using the OPEN() */
  139.         /* function to see if it is complete */
  140.         /* if it isn't then we BREAK out of this DO segment and */
  141.         /* wait again */
  142.  
  143.         IF FrmNumber == EndFrame THEN
  144.           IF OPEN( TESTF , InputDir || FrameName || FrmNumber ) THEN
  145.             DO
  146.                BOGUS = CLOSE( TESTF )
  147.                IF ((TOT_FRAMES // GOP_SIZE) > 0) & ,
  148.                    (GOPS_COMPLETE = TOT_GOPS - 1) THEN
  149.                   DO
  150.                     GOP_SIZE = TOT_FRAMES // GOP_SIZE
  151.                     LastGOPFrm = LastGOPFrm + 1
  152.                   END
  153.                ELSE IF ((TOT_FRAMES // GOP_SIZE) == 0) & ,
  154.                        (GOPS_COMPLETE = TOT_GOPS - 1) THEN
  155.                        LastGOPFrm = LastGOPFrm + 1
  156.             END
  157.           ELSE
  158.             BREAK
  159.  
  160.  
  161.  
  162.         /* First turn IFF-24 frames into .PPM files */
  163.         /* and delete the original IFF-24 frames if requested */
  164.  
  165.         DO x = (LastGOPFrm - GOP_SIZE) to (LastGOPFrm - 1)
  166.            FrmNumber = RIGHT( x ,LENGTH(StFrame),0)
  167.            SAY 'Converting Frame'FrmNumber'to PPM format'
  168.  
  169.            RC = 0
  170.            '24toPPM >NIL:' InputDir || FrameName || FrmNumber ,
  171.                      InputDir || FrameName || FrmNumber || '.ppm'
  172.  
  173.            /* Check to see if 24toppm failed due to wrong number */
  174.            /* of bitplanes and use ilbmtoppm instead */
  175.  
  176.            IF RC == 20 THEN
  177.              'ILBMtoPPM  <'InputDir || FrameName || FrmNumber ,
  178.                          '>'||InputDir || FrameName || FrmNumber || '.ppm'
  179.  
  180.            IF DelOldFrms == 'YES' THEN
  181.              'delete' InputDir || FrameName || FrmNumber
  182.         END
  183.  
  184.       'mpeg_encode -gop' GOPS_COMPLETE OutFile||'.param'
  185.  
  186.       GOPS_COMPLETE = GOPS_COMPLETE + 1
  187.  
  188.       /* Now Delete the PPM files */
  189.  
  190.       DO x = (LastGOPFrm - GOP_SIZE) to (LastGOPFrm - 1)
  191.          FrmNumber = RIGHT( x ,LENGTH(StFrame),0)
  192.          'delete' InputDir || FrameName || FrmNumber || '.ppm'
  193.       END
  194.  
  195.       Call Stats()
  196.  
  197.     END
  198.  
  199.  
  200. IF GOPS_COMPLETE == TOT_GOPS THEN
  201.    BREAK
  202.  
  203. 'wait' FrmDelay  /* Put in a delay so as not to absorb processor time */
  204.  
  205. END
  206.  
  207.  
  208.  
  209.  
  210. /* Now that all graphic files are done generating */
  211. /* combine all the GOPS into an MPEG file */
  212.  
  213.  
  214. /* Here is where we give the final command to mpeg_encode */
  215. /* which then combines the GOP's into a full MPEG-1 file */
  216.  
  217.  
  218. 'mpeg_encode -combine_gops' OutFile||'.param'
  219.  
  220. /* Now Delete the GOPS and we're done! */
  221. DO I = 0 to (TOT_GOPS - 1)
  222.   'delete' InputDir || OutFile || '.mpg' || '.gop.' || I
  223. END
  224.  
  225.  
  226. SAY '------------------------------'
  227. SAY '    Processing Complete!'
  228. SAY '------------------------------'
  229.  
  230. SAY
  231.  
  232.  
  233. /* Here is where the last little OK window pops up */
  234. /* if you don't like that, then just comment the following */
  235. /* line out of the program */
  236.  
  237. Call Request(300,100,"Processing Complete",,"OK",,)
  238.  
  239. EXIT
  240.  
  241.  
  242.  
  243.  
  244. /* ================================================================== */
  245. /* This is where the functions are defined */
  246. /* ================================================================== */
  247.  
  248.  
  249. /* This separates the FrameName and InputDir from the input string */
  250.  
  251. GetFrameName:
  252.  
  253.     IF LASTPOS('/' , FrameName ) > 0 THEN
  254.       DO
  255.         FileInDir = LEFT( FrameName, LASTPOS('/' , FrameName )-1 )
  256.         InputDir = LEFT( FrameName, LASTPOS('/' , FrameName ) )
  257.         FrameName = SUBSTR( FrameName, LASTPOS('/' , FrameName )+1 )
  258.       END
  259.     ELSE
  260.         InputDir = ''
  261.  
  262. RETURN 0
  263.  
  264.  
  265.  
  266. GetFileInDir:
  267.  
  268.     IF LASTPOS('/' , InputDir ) > 0 THEN
  269.         FileInDir = LEFT( InputDir, LASTPOS('/' , InputDir )-1 )
  270.     ELSE
  271.         FileInDir = ''
  272.  
  273. RETURN 0
  274.  
  275.  
  276.  
  277. /* This initializes the global variables in case there */
  278. /* is no MPEG.settings file to read them from */
  279.  
  280. InitGlobals:
  281.  
  282.     FrameName = 'Pic.'
  283.     StFrame = '0000'
  284.     EndFrame = '0030'
  285.     Xdim = 160
  286.     Ydim = 120
  287.     InputDir = 'input/'
  288.     FileInDir = 'input'
  289.     PATTERN = 'IPBP'
  290.     IQScale = 2
  291.     PQScale = 4
  292.     BQScale = 6
  293.     FrmDelay = 60
  294.     DelOldFrms = 'YES'
  295.     OutFile = 'Movie'
  296.  
  297.     GOPS_COMPLETE = 0
  298.  
  299. RETURN 0
  300.  
  301.  
  302.  
  303. /* This prints the Status to the CON: window */
  304.  
  305. Stats:
  306.     SAY ' '  /* This is a clear screen character */
  307.     SAY 'Easy_MPEG  Scott Tribbey 1994  All rights reserved'
  308.     SAY 'MPEG Stream Status'
  309.     SAY '--------------------------------------------------'
  310.     SAY 'Start Frame  :' FrameName || StFrame
  311.     SAY 'End Frame    :' FrameName || EndFrame
  312.     SAY 'Frame Width  :' Xdim
  313.     SAY 'Frame Height :' Ydim
  314.     SAY 'Input Dir.   :' InputDir
  315.     SAY 'Encode Patt. :' PATTERN
  316.     SAY 'IQScale      :' IQScale
  317.     SAY 'PQScale      :' PQScale
  318.     SAY 'BQScale      :' BQScale
  319.     SAY 'GOP_SIZE     :' GOP_SIZE
  320.     SAY 'Total Frames :' TOT_FRAMES
  321.     SAY 'Dir. Scan    :' FrmDelay 'sec.'
  322.     SAY 'Del Old Frms :' DelOldFrms
  323.     SAY 'Total GOPS   :' TOT_GOPS
  324.     SAY 'OutFile Name :' OutFile || '.mpg'
  325.     SAY '--------------------------------------------------'
  326.     SAY 'GOPS Complete:' GOPS_COMPLETE '(' (GOPS_COMPLETE / TOT_GOPS * 100) '% )'
  327.     SAY '--------------------------------------------------'
  328.     SAY
  329.     SAY
  330.  
  331. RETURN 0
  332.  
  333.  
  334. /* Store current MPEG parameters in MPEG.settings file */
  335.  
  336. SaveParams:
  337.  
  338.     OPEN( SETFILE,'MPEG.settings', 'W' )
  339.  
  340.     WRITELN( SETFILE , FrameName )
  341.     WRITELN( SETFILE , InputDir )
  342.     WRITELN( SETFILE , StFrame )
  343.     WRITELN( SETFILE , EndFrame )
  344.     WRITELN( SETFILE , Xdim )
  345.     WRITELN( SETFILE , Ydim )
  346.     WRITELN( SETFILE , OutFile )
  347.     WRITELN( SETFILE , FrmDelay )
  348.     WRITELN( SETFILE , DelOldFrms )
  349.     WRITELN( SETFILE , IQScale )
  350.     WRITELN( SETFILE , PQScale )
  351.     WRITELN( SETFILE , BQScale )
  352.     WRITELN( SETFILE , PATTERN )
  353.  
  354.     CLOSE( SETFILE )
  355.  
  356. RETURN 0
  357.  
  358.  
  359. /* Read MPEG parameters from MPEG.settings file */
  360.  
  361. ReadParams:
  362.  
  363.     OPEN( SETFILE,'MPEG.settings', 'R' )
  364.  
  365.     FrameName = READLN( SETFILE )
  366.     InputDir = READLN( SETFILE )
  367.     StFrame = READLN( SETFILE )
  368.     EndFrame = READLN( SETFILE )
  369.     Xdim = READLN( SETFILE )
  370.     Ydim = READLN( SETFILE )
  371.     OutFile = READLN( SETFILE )
  372.     FrmDelay = READLN( SETFILE )
  373.     DelOldFrms = READLN( SETFILE )
  374.     IQScale = READLN( SETFILE )
  375.     PQScale = READLN( SETFILE )
  376.     BQScale = READLN( SETFILE )
  377.     PATTERN = READLN( SETFILE )
  378.  
  379.     CLOSE( SETFILE )
  380.  
  381.  
  382. RETURN 0
  383.  
  384.  
  385.  
  386. /* Setup some MPEG parameters and calc. the number of GOPS */
  387. /* Calculate a reasonable GOP size ( at least 3 frames ) */
  388.  
  389. CalcGOPS:
  390.  
  391.     GOP_SIZE = LENGTH(PATTERN)
  392.  
  393.     I = 0
  394.  
  395.     DO I = I + 1 UNTIL GOP_SIZE >= 0
  396.        GOP_SIZE = I * LENGTH(PATTERN)
  397.  
  398.     END
  399.  
  400.  
  401.     IF EndFrame <= StFrame
  402.       THEN DO
  403.         EndFrame = StFrame + 1
  404.         Call Request(300,100,"You need more frames than that!",,"OK",,)
  405.       END
  406.  
  407.     TOT_FRAMES = EndFrame - StFrame + 1
  408.     TOT_GOPS = TRUNC( TOT_FRAMES / GOP_SIZE )
  409.  
  410.     IF TOT_FRAMES // GOP_SIZE ~= 0 THEN
  411.          TOT_GOPS = TOT_GOPS + 1
  412.  
  413.  
  414.     IF TOT_GOPS == 0
  415.      THEN
  416.        DO
  417.          Call Request(300,100,"You need more frames than that!",,"OK",,)
  418.          /* SAY
  419.          SAY ' Hey you''ll need more frames than that!!!'
  420.          SAY
  421.          EXIT */
  422.        END
  423.  
  424. RETURN 0
  425.  
  426.  
  427.  
  428.  
  429. /* This function creates the .param file which contains the operational */
  430. /* parameters for the mpeg_encode program */
  431.  
  432. WriteParamFile:
  433.  
  434.     SAY 'Compiling mpeg_encode Parameter File...'
  435.     SAY
  436.  
  437.     OPEN( PARMFILE, Outfile || '.param', 'W' )
  438.  
  439.     WRITELN( PARMFILE , '# This parameter file created by Easy_MPEG.rexx' )
  440.     WRITELN( PARMFILE , '# An Arexx program by Scott Tribbey 1994' )
  441.  
  442.     WRITELN( PARMFILE , '' )
  443.     WRITELN( PARMFILE , '' )
  444.     WRITELN( PARMFILE , 'PATTERN   ' || PATTERN )
  445.     WRITELN( PARMFILE , 'OUTPUT    ' || InputDir || OutFile || '.mpg' )
  446.     WRITELN( PARMFILE , '' )
  447.     WRITELN( PARMFILE , 'BASE_FILE_FORMAT   PPM' )
  448.     WRITELN( PARMFILE , 'GOP_SIZE   ' GOP_SIZE )
  449.     WRITELN( PARMFILE , 'SLICES_PER_FRAME   1  ' )
  450.     WRITELN( PARMFILE , '' )
  451.     WRITELN( PARMFILE , 'PIXEL  HALF' )
  452.     WRITELN( PARMFILE , 'RANGE  10' )
  453.     WRITELN( PARMFILE , 'PSEARCH_ALG     LOGARITHMIC' )
  454.     WRITELN( PARMFILE , 'BSEARCH_ALG     CROSS2' )
  455.     WRITELN( PARMFILE , 'IQSCALE         'IQScale )
  456.     WRITELN( PARMFILE , 'PQSCALE         'PQScale )
  457.     WRITELN( PARMFILE , 'BQSCALE         'BQScale )
  458.     WRITELN( PARMFILE , '' )
  459.     WRITELN( PARMFILE , 'REFERENCE_FRAME ORIGINAL' )
  460.     WRITELN( PARMFILE , 'FORCE_ENCODE_LAST_FRAME' )
  461.     WRITELN( PARMFILE , '' )
  462.     WRITELN( PARMFILE , 'YUV_SIZE       '||Xdim||'x'||Ydim )
  463.     WRITELN( PARMFILE , 'INPUT_DIR       '||FileInDir )
  464.     WRITELN( PARMFILE , 'INPUT' )
  465.     WRITELN( PARMFILE , FrameName || '*' || '.ppm   ' '[' || ,
  466.                         StFrame || '-' || EndFrame || ']')
  467.     WRITELN( PARMFILE , 'END_INPUT' )
  468.     WRITELN( PARMFILE , 'INPUT_CONVERT  *' )
  469.  
  470.     CLOSE( PARMFILE )
  471.  
  472. RETURN 0
  473.  
  474.  
  475.  
  476. RunHost:
  477.  
  478.     if ~show('l', "rexxarplib.library") then do
  479.     check = addlib('rexxarplib.library',0,-30,0)
  480.     end
  481.  
  482.     if ~show('l', "rexxsupportlib.library") then do
  483.     check = addlib('rexxsupport.library',0,-30,0)
  484.     end
  485.  
  486.     ADDRESS COMMAND
  487.  
  488.     /* The following command is the only way to use the createhost() */
  489.     /* function without locking up the script */
  490.  
  491.     Call OPENPORT(MPEGPORT)
  492.  
  493.     'Run ' 'SYS:Rexxc/rx ''Call createhost(MPEGHOST, MPEGPORT,)'''
  494.  
  495.     Call delay(100)  /* delay to allow the host to get set up */
  496.  
  497.     idcmp = 'CLOSEWINDOW+GADGETDOWN+GADGETUP'
  498.     flags = 'WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH'
  499.     call OpenWindow(MPEGHOST, 50, 50, 340, 200, idcmp, flags, "Easy_MPEG 1.01 Scott Tribbey 1994")
  500.  
  501.     call SetAPen(MPEGHOST,1)
  502.  
  503.     /* Now Add the gadgets */
  504.  
  505.     call AddGadget(MPEGHOST,120 ,15 ,00 ,FrameName ,"%l STRING %d %g",200 )
  506.     call AddGadget(MPEGHOST,120 ,30 ,01 ,InputDir ,"%l STRING %d %g",200 )
  507.     call AddGadget(MPEGHOST,120 ,45 ,02 ,StFrame ,"%l STRING %d %g",100 )
  508.     call AddGadget(MPEGHOST,120 ,60 ,03 ,EndFrame ,"%l STRING %d %g",100 )
  509.     call AddGadget(MPEGHOST,135 ,75 ,04 ,Xdim ,"%l STRING %d %g",40 )
  510.     call AddGadget(MPEGHOST,205 ,75 ,05 ,Ydim ,"%l STRING %d %g",40 )
  511.     call AddGadget(MPEGHOST,120 ,120 ,06 ,OutFile ,"%l STRING %d %g",200 )
  512.     call AddGadget(MPEGHOST,120 ,135 ,07 ,FrmDelay ,"%l STRING %d %g",40 )
  513.     call AddGadget(MPEGHOST,120 ,150 ,08,"Del. Old Frames" ,"%l STRING %d")
  514.     call AddGadget(MPEGHOST,252 ,170 ,09,"Start\Scanning" ,"%l STRING %d")
  515.     call AddGadget(MPEGHOST,120 ,170 ,10,"Quit\Program" ,"QUIT")
  516.     call AddGadget(MPEGHOST,244 ,45 ,11,"File\Requester" ,"%l STRING %d")
  517.     call AddGadget(MPEGHOST,135 ,90 ,12,IQScale ,"%l STRING %d %g",40 )
  518.     call AddGadget(MPEGHOST,205 ,90 ,13,PQScale ,"%l STRING %d %g",40 )
  519.     call AddGadget(MPEGHOST,275 ,90 ,14,BQScale ,"%l STRING %d %g",40 )
  520.     call AddGadget(MPEGHOST,120 ,105 ,15,PATTERN ,"%l STRING %d %g",200 )
  521.  
  522.  
  523.     /* Now Add the gadget labels */
  524.  
  525.     call Move(MPEGHOST,10,22)
  526.     call Text(MPEGHOST,"  Frame Name:")
  527.     call Move(MPEGHOST,10,37)
  528.     call Text(MPEGHOST,"   Input Dir:")
  529.     call Move(MPEGHOST,10,52)
  530.     call Text(MPEGHOST," Start Frame:")
  531.     call Move(MPEGHOST,10,67)
  532.     call Text(MPEGHOST,"   End Frame:")
  533.     call Move(MPEGHOST,10,82)
  534.     call Text(MPEGHOST,"  Resolution: X")
  535.     call Move(MPEGHOST,190,82)
  536.     call Text(MPEGHOST,"Y")
  537.  
  538.     call Move(MPEGHOST,10,97)
  539.     call Text(MPEGHOST,"Quant. Scale: I")
  540.     call Move(MPEGHOST,190,97)
  541.     call Text(MPEGHOST,"P")
  542.     call Move(MPEGHOST,260,97)
  543.     call Text(MPEGHOST,"B")
  544.     call Move(MPEGHOST,10,112)
  545.     call Text(MPEGHOST,"Frm. Pattern:")
  546.  
  547.     call Move(MPEGHOST,10,127)
  548.     call Text(MPEGHOST,"    Out File:")
  549.     call Move(MPEGHOST,10,142)
  550.     call Text(MPEGHOST,"   Dir. Scan:")
  551.     call Move(MPEGHOST,170,142)
  552.     call Text(MPEGHOST,"Sec.")
  553.  
  554.     CALL MessageLoop()
  555.  
  556.     call Exit(MPEGHOST)
  557.  
  558.     Call CLOSEPORT(MPEGPORT)
  559.  
  560.     IF QUIT = 1 THEN EXIT(0)
  561.  
  562.  
  563. RETURN 0
  564.  
  565.  
  566.  
  567.  
  568.  
  569. MessageLoop:
  570.  
  571.  
  572. /* MAIN message loop */
  573.  
  574. keep_going=1
  575. DO WHILE keep_going=1
  576.  
  577.  
  578. /* Wait for at least one message to arrive */
  579.  
  580.   t=WAITPKT(MPEGPORT)
  581.  
  582. /* process *ALL* the messages waiting at this port */
  583.  
  584.   DO ff=1
  585.     p=GETPKT(MPEGPORT)
  586.  
  587.  
  588. /* p=NULL means not more messages at this port.
  589.   This is the *ONLY* time you should leave this loop! */
  590.  
  591.     IF p='0000 0000'x THEN LEAVE ff    /* message port empty */
  592.  
  593. /* get the message from the the port packet */
  594.  
  595.     command=GETARG(p)
  596.  
  597.  
  598. /* REPLY() as soon as you can, as soon as you are through extracting
  599.    data from the packet with GETARG() */
  600.  
  601.     t=REPLY(p,0)
  602.  
  603.  
  604. /* Ignore any messages received after the CLOSEWINDOW */
  605.  
  606.     IF keep_going=0 THEN ITERATE ff
  607.  
  608.  
  609.  
  610. /* now we can see what the message contains, and act on it */
  611.  
  612.     PARSE VAR command arg1' 'arg2' 'arg3' 'arg4' '
  613.     SELECT
  614.       WHEN arg1='CLOSEWINDOW' | arg1 = 'QUIT' THEN
  615.         DO
  616.           keep_going=0
  617.           QUIT = 1
  618.         END
  619.  
  620.       WHEN arg1='GADGETUP' THEN
  621.         DO
  622.           SELECT
  623.           WHEN arg2='STRING' THEN
  624.             DO
  625.              SELECT
  626.                WHEN arg3 = 0  THEN FrameName = arg4
  627.                WHEN arg3 = 1  THEN
  628.                  DO
  629.                     InputDir = arg4
  630.                     Call GetFileInDir()
  631.                  END
  632.  
  633.                WHEN arg3 = 2  THEN StFrame = arg4
  634.                WHEN arg3 = 3  THEN EndFrame = arg4
  635.                WHEN arg3 = 4  THEN Xdim = arg4
  636.                WHEN arg3 = 5  THEN Ydim = arg4
  637.                WHEN arg3 = 6  THEN OutFile = arg4
  638.                WHEN arg3 = 7  THEN FrmDelay = arg4
  639.  
  640.                WHEN arg3 = 8  THEN
  641.                 IF DelOldFrms = 'YES' THEN
  642.                   DelOldFrms = 'NO'
  643.                 ELSE
  644.                   DelOldFrms = 'YES'
  645.  
  646.                WHEN arg3 = 9  THEN keep_going=0
  647.                WHEN arg3 = 10 THEN FrmDelay = arg4
  648.  
  649.  
  650.                WHEN arg3 = 11 THEN Call GetBaseFile()
  651.                WHEN arg3 = 12 THEN IQScale = arg4
  652.                WHEN arg3 = 13 THEN PQScale = arg4
  653.                WHEN arg3 = 14 THEN BQScale = arg4
  654.                WHEN arg3 = 15 THEN PATTERN = arg4
  655.  
  656.              OTHERWISE
  657.              END
  658.                 Call CalcGOPS()
  659.                 Call Stats()
  660.             END
  661.  
  662.           OTHERWISE
  663.           END
  664.  
  665.         END
  666.  
  667.  
  668.       OTHERWISE DO
  669.  
  670.         SAY 'arg1 'arg1
  671.         SAY 'arg2 'arg2
  672.         SAY 'arg3 'arg3
  673.  
  674.       END
  675.  
  676.     END
  677.  
  678.   END
  679. END
  680.  
  681.  
  682. RETURN 0
  683.  
  684.  
  685. /* This is where we use the ARP file requester to get the Base Filename */
  686.  
  687. GetBaseFile:
  688.  
  689.     FileName = GetFile(100,100,FileInDir,,,)
  690.  
  691.     IF FileName ~= '' THEN
  692.       DO
  693.         FrameName = FileName
  694.         Call GetFrameName()
  695.  
  696.         call RemoveGadget(MPEGHOST,00)
  697.         call RemoveGadget(MPEGHOST,01)
  698.  
  699.         call AddGadget(MPEGHOST,120 ,15 ,00 ,FrameName ,"%l STRING %d %g",200 )
  700.         call AddGadget(MPEGHOST,120 ,30 ,01 ,InputDir ,"%l STRING %d %g",200 )
  701.       END
  702.  
  703. RETURN 0
  704.